#!/usr/bin/python3
import urllib.request
import json
import threading
import time
def getData(x):
    data = {"pagesize": 1000,
    "pageindex": x,
    "type": 2,
    "txt1":"",
    "CorpCode":"",
    "CorpName":"",
    "LegalMan":"",
    "CertTypeNum":"",
    "AreaCode":""}
    data_string=urllib.parse.urlencode(data)
    last_data=bytes(data_string,encoding='utf-8')
    f = urllib.request.urlopen("http://61.190.70.122:8003/epoint-mini/rest/function/searchSNQY",data=last_data)
    ltp_data = json.dumps(json.loads(f.read().decode('utf-8'))['all']['listinfo'])
    print(ltp_data)

def checkDir(dir):
    allSourceFiles = listDir(dir,extensions=["txt"],reuslts = [])
    m = 70
    for x in allSourceFiles:
        t = os.stat(x).st_atime
        m = min(int(time.time()-t), m)
    print(f"{dir}:{m}")
    if m > 60:
        messagebox.showinfo("提示",f"{dir}出错")
    return m > 60
    
class myThread (threading.Thread):
    def __init__(self, threadID, name, counter):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name
        self.counter = counter
    def run(self):
        print ("开启线程： " + self.name)
        # 获取锁，用于线程同步
        threadLock.acquire()
        getData(self.counter)
        print_time(self.name, self.counter, 3)
        # 释放锁，开启下一个线程
        threadLock.release()

def print_time(threadName, delay, counter):
    print ("%s: %s" % (threadName, time.ctime(time.time())))

threadLock = threading.Lock()
threads = []
for x in range(1,6):
    thread = myThread(x, f"Thread-{x}", x)
    thread.start()
    threads.append(thread)
    
for t in threads:
    t.join()
print ("退出主线程")